package 代码记录.校招笔试真题.笔试真题_2022.欧克云链;

import java.util.ArrayList;
import java.util.List;


public class 验证二叉搜索树 {
    List<Integer> list = new ArrayList<>();
    public boolean isValidBST (TreeNode root) {
        inOrder(root);
        for(int i = 1;i < list.size();i++){
            if(list.get(i - 1) > list.get(i)){
                return false;
            }
        }
        return true;
    }
    private void inOrder(TreeNode root){
        if(root == null){
            return;
        }
        inOrder(root.left);
        list.add(root.val);
        inOrder(root.right);
    }

    private class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;
        }
    }
}
